//
//  SLNoDataView.swift
//  sulit-loan
//
//  Created by 王刚锋 on 2025/4/17.
//  Copyright © 2025 coolBoy. All rights reserved.
//

import UIKit

import UIKit
import SnapKit

class SLNoDataView: UIView {
    
    // MARK: - UI Components
    private let icon: UIImageView = {
        let iv = UIImageView()
        iv.image = UIImage(named: "icon-no record") // 替换为实际图片名
        iv.contentMode = .scaleAspectFit
        return iv
    }()
    
    
    private let noRecordLabel: UILabel = {
        let label = UILabel()
        label.text = "No record"
        label.font = UIFont.systemFont(ofSize: 16, weight: .regular)
        label.textColor = rgba(hex: "#8F8F8F")
        return label
    }()
    
    private let applyButton: UIButton = {
        let button = UIButton(type: .system)
        button.setTitle("Apply Now", for: .normal)
        button.titleLabel?.font = SLFontConfig.medium16
        button.setTitleColor(.white, for: .normal)
        button.backgroundColor = rgba(hex: "#1608EC")
        button.layer.cornerRadius = 22
        button.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
        return button
    }()
    @objc private func buttonClick(){
        let url = "sul://rivers"
        jump(url: url)
    }
    
    // MARK: - Initialization
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - Setup
    private func setupUI() {
        backgroundColor = .clear
        
        // 添加子视图
        addSubview(icon)
        addSubview(noRecordLabel)
        addSubview(applyButton)
        
        // 设置约束
        icon.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.width.equalTo(200)
            make.height.equalTo(150)
        }
        
        
        noRecordLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(icon.snp.bottom).offset(0)
        }
        
        applyButton.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(noRecordLabel.snp.bottom).offset(35)
            make.width.equalTo(183)
            make.height.equalTo(44)
        }
    }
}
